package com.hs.telepass.ui;

import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.hs.teleform.R;
import com.hs.telepass.controller.TaskController;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by dasunsy on 15/7/14.
 */
public class InputPhoneNumberDialog extends DialogFragment {

    @InjectView(R.id.btn_cancel)
    Button btnCancel;
    @InjectView(R.id.tv_title)
    TextView tvTitle;
    @InjectView(R.id.et_input_num)
    EditText etInputNum;
    @InjectView(R.id.iv_clear)
    ImageView ivClear;
    @InjectView(R.id.button_commit)
    Button buttonCommit;

    private String mTitle = "";
    /**用于社团绑定的storeId*/
    private int storeId;
    private OnCancelClickListerner cancelClickListerner;
    private OnSureClickListerner sureClickListerner;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.input_info_dialog, container);
        ButterKnife.inject(this, view);
        setViews();

        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        setCancelable(false);
        return view;
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }

    private void setViews(){
        tvTitle.setText(mTitle);
        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cancelClickListerner.onClick();
                dismiss();
            }
        });

    }

    @OnClick(R.id.iv_clear)
    void onClear(){
        etInputNum.setText("");
    }

    @OnClick(R.id.button_commit)
    void onCommit(){
        //todo 获取机型
        TaskController.getInstance().setDeviceToken(getActivity(), storeId, etInputNum.getText().toString(), "android");
        dismiss();
    }


    public void setStoreId(int storeId){
        this.storeId = storeId;
    }

    public void setOnSureClickListener(OnSureClickListerner sureClickListener){
        this.sureClickListerner = sureClickListener;
    }

    public void setOnCancelClickListener(OnCancelClickListerner cancelClickListener){
        this.cancelClickListerner = cancelClickListener;
    }

    public void setTitle(String orgName){
        this.mTitle = orgName;
    }

    public interface OnCancelClickListerner{
        void onClick();
    }

    public interface OnSureClickListerner{
        void onClick();
    }
}
